package com.vodone.v1pin.navigator.view.pm
{
	
	import com.vodone.v1pin.core.model.MainModelLocator;
	import com.vodone.v1pin.navigator.delegate.NavigatorConvertUtil;
	import com.vodone.v1pin.navigator.delegate.NavigatorDelegate;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;

	/**
	* 请求成功时派发 
	*/	
	[Event(name="complete")]
	/**
	* 请求失败时派发
	*/	
	[Event(name="fault")]
	/**
	* 开始请求时派发
	*/	
	[Event(name="startLoad")]
	
	public class NavigatorPM extends EventDispatcher
	{
		public static const STARTLoad:String = "startLoad";
		public static const FAULT:String = "fault";
		
		public var navigatorList:Array;
		
		public var navType:String;
		public function NavigatorPM(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function doSearch( type:String = "main" ):void
		{
			navType = type;
			NavigatorDelegate.getNavigator(resultHandler,type,faultHandler);
			this.dispatchEvent( new Event( STARTLoad ) ); 
		}
		
		public function resultHandler( obj:Object ):void
		{
			navigatorList = NavigatorConvertUtil.getNavList( obj , navType);
			var dict:Dictionary = MainModelLocator.getInstance().navDict;
			this.dispatchEvent( new Event( Event.COMPLETE ));
		}
		
		private function faultHandler( obj:Object ):void
		{
			MainModelLocator.getInstance().debugStr += "导航加载失败:" + "\n";
			this.dispatchEvent( new Event( "fault" ));
		}
	}
}